<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../component/layui/css/layui.css"/>
    <link href="../../admin/css/pearCommon.css" rel="stylesheet"/>
    <style>
        body{
            margin: 20px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="javascript:void(0);">
    <div  class="mainBox">
        <div class="layui-row" style="margin: 15px;">
            <div class="layui-col-md12 layui-col-sm12">
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" required  lay-verify="required" placeholder="请输入角色名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md12 layui-col-sm12">
                <div class="layui-form-item">
                    <label class="layui-form-label">类型标识</label>
                    <div class="layui-input-block">
                        <input type="text" name="type" required  lay-verify="required" placeholder="请输入角色标识" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-col-md12 layui-col-sm12">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input value="1" type="checkbox" lay-text="启用|禁用" name="status" checked lay-skin="switch">
                </div>
            </div>

            <div class="layui-form-item layui-col-md12 layui-col-sm12 layui-form-text">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea name="description" placeholder="请输入字典描述" class="layui-textarea"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div  class="bottom">
        <div class="button-container">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">重置</button>
        </div>
    </div>

</form>

<script src="../../component/layui/layui.js"></script>
<script>
    //Demo
    layui.use(['form','layer','jquery'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        //监听提交
        form.on('submit(formDemo)', function(data){

            if(data.field.status!="1"){
                data.field.status="0";
            }

            $.ajax({
                url:'/system/dictType/save',
                type:'post',
                dataType:'json',
                data:JSON.stringify(data.field),
                contentType: 'application/json; charset=UTF-8',
                success:function(result){
                    if(result.code==200){
                        layer.msg(result.msg,{icon:1,time:1000},function(){

                            //关闭当前窗体
                            parent.layui.table.reload('dictTypeTable');
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);

                        });
                    }else{
                        layer.msg(result.msg,{icon:2,time:1000});
                    }
                }
            });

        });
    });
</script>
</body>
</html>